Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws-xray-sdk-express

Package Overview
Dependencies
Maintainers
13
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-xray-sdk-express

AWS X-Ray Middleware for Express (Javascript)

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
323K
increased by0.93%
Maintainers
13
Weekly downloads
 
Created

What is aws-xray-sdk-express?

The aws-xray-sdk-express npm package is a middleware for Express.js applications that integrates with AWS X-Ray to trace and analyze requests. It helps in monitoring and debugging applications by providing detailed insights into the performance and behavior of your application.

What are aws-xray-sdk-express's main functionalities?

Automatic Request Tracing

This feature allows you to automatically trace incoming HTTP requests. The middleware captures the request and response cycle, creating segments that can be visualized in the AWS X-Ray console.

const express = require('express');
const AWSXRay = require('aws-xray-sdk');
const app = express();

app.use(AWSXRay.express.openSegment('MyApp'));

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.use(AWSXRay.express.closeSegment());

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Custom Subsegments

This feature allows you to create custom subsegments within a segment. This is useful for tracing specific parts of your code, such as database queries or external API calls.

const express = require('express');
const AWSXRay = require('aws-xray-sdk');
const app = express();

app.use(AWSXRay.express.openSegment('MyApp'));

app.get('/custom', (req, res) => {
  const segment = AWSXRay.getSegment();
  const subsegment = segment.addNewSubsegment('customSubsegment');
  // Perform some operations
  subsegment.close();
  res.send('Custom Subsegment');
});

app.use(AWSXRay.express.closeSegment());

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Error Capturing

This feature allows you to capture and record errors that occur during the request lifecycle. The errors are sent to AWS X-Ray, where they can be analyzed to identify and fix issues.

const express = require('express');
const AWSXRay = require('aws-xray-sdk');
const app = express();

app.use(AWSXRay.express.openSegment('MyApp'));

app.get('/error', (req, res) => {
  const segment = AWSXRay.getSegment();
  try {
    throw new Error('Something went wrong!');
  } catch (err) {
    segment.addError(err);
    res.status(500).send('Internal Server Error');
  }
});

app.use(AWSXRay.express.closeSegment());

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Other packages similar to aws-xray-sdk-express

Keywords

FAQs

Package last updated on 11 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc